<script setup lang="ts">
import KnowledgeCard from './KnowledgeCard.vue'
import {ref} from 'vue'
import {KnowledgeType,KnowledgeListType,KnowledgeParams } from '@/types/consult'
import { getKnowLedgePageAPI} from '@/services/consult'

//接收父组件传来的数据
const props = defineProps<{
  type:KnowledgeType
}>()


const list = ref<KnowledgeListType>([])
const loading = ref(false);
const finished = ref(false);
const params = ref<KnowledgeParams>({
  type:props.type,
  current:1,
  pageSize:10
})

const onLoad = async()=>{
  const res = await getKnowLedgePageAPI(params.value)
  console.log(res);
  list.value.push(...res.data.rows)
  params.value.current++
  //加载结束，把loading改为false
  loading.value = false
  //加载完成,将finished改为true
  if(params.value.current > res.data.pageTotal){
    finished.value = true
  }
 }
</script>

<template>
  <div class="knowledge-list">
    <van-list
      v-model:loading="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
    <knowledge-card v-for="(item,i) in list" :key="i" :item="item"/>
  </van-list>
  </div>
</template>

<style lang="scss" scoped>
.knowledge-list {
  padding: 0 15px;
}
</style>
